<?php
declare (strict_types=1);

namespace app\common\model;

use cores\BaseModel;

/**
 * 微信消息订阅模板
 * Class WxnoticeTemplate
 * @package app\common\model\user
 */
class WxnoticeTemplate extends BaseModel
{
    // 定义表名
    protected $name = 'wxnotice_template';

    // 定义主键
    protected $pk = 'id';

    protected $updateTime = false;

    /**
     * 微信消息订阅发货模板
     * @param null $type
     * @return array|string[]|\string[][]
     */
    public static function wxMessageTemplate(array $type = [])
    {
        $filter = [];
        if($type){
            $filter[] = ['type', 'in', $type];
        }
        $template = (new static)->field('name,type,type as id,template_id,store_id,reminder,suggest')
            ->where($filter)->select()->toArray();
        if($template){
            $template = array_column($template,null,'type');
        }
        return $template;
    }

    /**
     * 新增记录
     * @param int $scene
     * @param array $data
     * @param array $describeParam
     */
    public static function add(array $data)
    {
        $model = new static;
        $model->save(array_merge([
            'store_id' => $model::$storeId
        ], $data));
    }

    /**
     * 微信模板获取模板id
     * @param null $type
     * @return array|string[]|\string[][]
     */
    public static function getSubscriptionTypeByTemplate(array $template = [])
    {
        $filter = [];
        if($template){
            $filter[] = ['template_id', 'in', $template];
        }
        $template = (new static)->field('name,type,template_id,store_id,reminder,suggest')
            ->where($filter)->select()->toArray();
        return $template;
    }

}
